﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Rbac.API.Filters;
using Rbac.Contracts.DTO.InPut;
using Rbac.Contracts.DTO.OutPut;
using Rbac.Contracts.Interface;
using Rbac.Domain.Entity;
using Rbac.Share.consts;

namespace Rbac.API.Controllers
{
	/// <summary>
	/// 权限管理
	/// </summary>
	[Route("api/[controller]/[action]")]
	[ApiController]
	[Authorize]
	public class PeimissionController : ControllerBase
	{
		private readonly IPermissionServer _permissionServer;
		public PeimissionController(IPermissionServer permissionServer)
		{
			_permissionServer = permissionServer;
		}
		/// <summary>
		/// 权限添加
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		/// <exception cref="NotImplementedException"></exception>
		[HttpPost]
		public Results<int> Add(PermissionInPut input)
		{
			return Results<int>.DataResult(_permissionServer.Add(input));
		}
		/// <summary>
		/// 权限删除
		/// </summary>
		/// <param name="idList"></param>
		/// <returns></returns>
		/// <exception cref="NotImplementedException"></exception>
		[HttpDelete]
		public Results<int> Delete(params int[] idList)
		{
			return Results<int>.DataResult(_permissionServer.Delete(idList.ToArray()));
		}
		/// <summary>
		/// 获取权限查询
		/// </summary>
		/// <param name="pName"></param>
		/// <returns></returns>
		/// <exception cref="NotImplementedException"></exception>
		[HttpGet]
		//[RbacAuthorize(AuthorizePolicyName.AdminAndCustomer)]
		public Results<List<PermissionOutPut>> GetPermissionOutPuts(string? pName)
		{
			return Results<List<PermissionOutPut>>.DataResult(_permissionServer.GetPermissionOutPuts(pName));
		}
		/// <summary>
		/// 权限修改
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		/// <exception cref="NotImplementedException"></exception>
		[HttpPut]
		public Results<int> Update(PermissionInPut input)
		{
			return Results<int>.DataResult(_permissionServer.Update(input));

		}
		/// <summary>
		/// 控制按钮显示
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		[HttpPost]
		public Results<bool> ShowButton([FromBody] ShowButtonInput input)
		{
			return Results<bool>.DataResult(_permissionServer.ShowButton(input));

		}
	}
}
